<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="tpl :: common_head()"></th:block>
    <link rel="stylesheet" type="text/css" href="../../assets/libs/videoUpload/pictureUpload.css"/>
    <script src="../../assets/libs/videoUpload/pictureUpload.js"></script>
    <title>产废单位认证审核</title>
</head>
<body th:object="${obj}" th:with="entrance='/system/productWasteOrgVerify/index'">
<th:block th:replace="tpl :: common_body(~{::.main-right})">
    <div class="main-right">
        <h1 class="main-right-h1">产废单位认证审核编辑</h1>
        <ul class="main-right-tab">
            <li><a href="index">列表</a></li>
            <li class="selected" th:if="*{id==null}">新增</li>
            <li class="selected" th:if="*{id!=null}">编辑</li>
        </ul>
        <form class="form" method="POST" onsubmit="return fileCheck()">
            <fieldset>
                <legend>信息</legend>
                <dl>
                    <dt>企业名称</dt>
                    <dd>
                        <input type="text" th:field="*{name}" data-verify="required(1)"/>
                    </dd>
                    <dt>所属行业</dt>
                    <dd>
                        <select class="js-example-basic-single" th:field="*{industry}">
                            <option th:each="op:*{@dictService.getByType('org_industry')}" th:value="${op.label}"
                                    th:text="${op.label}"></option>
                        </select>
                    </dd>
                    <dt>法定代表人</dt>
                    <dd>
                        <input type="text" th:field="*{legalRepresentative}" data-verify="required(1)"/>
                    </dd>
                    <dt>省</dt>
                    <dd>
                        <select th:field="*{province}" class="js-example-basic-single" onchange="select1()" style="width: 400px">
                            <option th:if="*{province!=null}" th:value="*{@areaService.getByName(province)}" th:text="*{province}"></option>
                            <option th:each="op:${areaList}" th:value="${op.id}" th:text="${op.text}"></option>
                        </select>
                    </dd>
                    <dt>市</dt>
                    <dd>
                        <select th:field="*{city}" class="js-example-basic-single" onchange="select2()" data-verify="required(1)" style="width: 400px" >
                            <option th:if="*{city!=null}"  th:value="*{@areaService.getByName(city)}" th:text="*{city}"></option>
                        </select>
                    </dd>
                    <dt>区</dt>
                    <dd>
                        <select th:field="*{area}" class="js-example-basic-single" data-verify="required(1)" style="width: 400px">
                            <option th:if="*{area!=null}" th:value="*{@areaService.getByName(area)}" th:text="*{area}"></option>
                        </select>
                    </dd>
                    <dt>地址</dt>
                    <dd>
                        <input type="text" th:field="*{address}" data-verify="required(1)"/>
                    </dd>
                    <dt>营业执照注册号</dt>
                    <dd>
                        <input type="text" th:field="*{licenseNumber}" data-verify="required(1)"/>
                    </dd>
                    <dt>年产危废规模</dt>
                    <dd>
                        <select class="js-example-basic-single" th:field="*{wasteScale}">
                            <option th:each="op:*{@dictService.getByType('org_waste_scale')}" th:value="${op.label}"
                                    th:text="${op.label}"></option>
                        </select>
                    </dd>
                    <div id="uploadFile">
                        <div th:id="file+${attachStat.index}" th:if="${attachStr!=null and attachStr!=''}"
                             th:each="attachObj,attachStat:${attach}">
                            <dt>危废清单</dt>
                            <dd>
                                <a target="_blank" th:href="${@imageService.getImageBasePath()+attachObj}" th:text="${attachObj}"></a>
                                <a th:href="'javascript:deletes('+${attachStat.index}+');'" style="margin-left:150px">删除</a>
                            </dd>
                        </div>
                    </div>

                    <div id="multiImg">
                        <div id="pic0">
                            <dt>文件上传</dt>
                            <dd>
                                <img id="coverImage0" onclick="showImage('coverImage0','wasteList')" style="width:200px"
                                     src="../../assets/images/add.png"/>
                            </dd>
                        </div>
                    </div>
                </dl>
                <input type="hidden" name="attachStr" id="attachStr" th:value="${attachStr}">
                <input type="submit" value="提交"/>
            </fieldset>
        </form>
    </div>
</th:block>
</body>
<script>
    var attachList;
    window.onload = function () {
        if ($("#attachStr").val().split(",").length > 0) {
            attachList = $("#attachStr").val().split(",");
        } else {
            attachList = new Array();
        }
    }

    function deletes(i) {
        delete attachList[i];
        $("#file" + i).remove();
    }

    function fileCheck() {
        $('#attachStr').val(attachList.join(','))
    }

    var index = "";

    function close() {
        layer.close(index);
    }

    function showImage(image, type) {
        index = layer.open({
            type: 2,
            area: ['1240px', '500px'],
            title: "文件上传",
            shade: 0.6,
            scrollbar: false,
            fixed: true,
            maxmin: true,
            content: "../show/showFilePage/" + type + "/" + image
        });
    }



    function select1() {
        var parentId = $('#province').val();
        $.ajax({
            url: './getAreaList?parentId=' + parentId,
            type: 'get',
            dataType: 'json',
            success: function (data) {
                var oldSelect= $('#city').val();
                $('#city').removeAttr("disabled");
                $('#city').empty();
                $('#city').select2({
                    data: data,
                    cache: false
                });
                $('#city').val(oldSelect).trigger('change');
            }
        });
        select2();
    }

    function select2() {
        var parentId = $('#city').val();
        if (typeof(parentId) != "undefined"){
            $.ajax({
                url: './getAreaList?parentId=' + parentId,
                type: 'get',
                dataType: 'json',
                success: function (data) {
                    var oldSelect= $('#area').val();
                    $('#area').empty();
                    $("#area").select2({
                        data: data
                    });
                    $('#area').val(oldSelect).trigger('change');
                }
            });
        }

    }

    $(document).ready(function () {
        select1();
    });
</script>
<style>
    .form dt {
        width: 135px;
    }
</style>
</html>